<?php
/**
 * Description: 国考宣言
 * User: devforma
 * Date: 2016/11/17
 * Time: 10:19
 */
class SetXuanyan implements iController {

    /**
     * api请求处理主函数
     * @param array $queryArgs 就是$_REQUEST变量
     * @return array api返回结果，必须含response_code
     */
    public function output($queryArgs) {
        global $uddb;

        if (validateUser($queryArgs) !== 1 || empty($queryArgs['xuanyan'])) {
            return genOutput(1000);
        }

        $exists = $uddb->getVar('SELECT `id` FROM `user2016_xuanyan` WHERE `user_id`=:uid', [':uid' => $queryArgs['user_id']]);
        if ($exists) {
            $uddb->update('user2016_xuanyan', ['xuanyan' => $queryArgs['xuanyan']], ['id' => $exists]);
        } else {
            $uddb->insert('user2016_xuanyan', ['user_id' => $queryArgs['user_id'], 'xuanyan' => $queryArgs['xuanyan']]);
        }

        return genOutput(1);
    }
}